#include "monitor.h"
#include "descriptor_tables.h"
#include "timer.h"
#include "paging.h"
#include "multiboot.h"
#include "fs.h"
#include "initrd.h"
#include "task.h"
#include "syscall.h"

extern u32int placement_address;
u32int initial_esp;


int kmain(struct multiboot *mboot_ptr, u32int initial_stack)
{
    initial_esp = initial_stack;
    // Initialise all the ISRs and segmentation
    init_descriptor_tables();
    // Initialise the screen (by clearing it)
    monitor_clear();
    monitor_write("  ___               \n");
    monitor_write(" |    \\ /  \\    /   \n");
    monitor_write(" |__   |     \\/     \n");
    monitor_write("    |  |    /  \\    \n");
    monitor_write("  __|  |  /      \\  \n");
    monitor_write("                     \n");
    monitor_write(" <<<Version v0.03>>> \n");
    // Initialise the PIT to 100Hz
    monitor_write("Starting a 100Hz PIT timer...\n");
    init_timer(50);
    
    monitor_write("Initializing paging...\n");
    initialise_paging();

    monitor_write("Starting multitasking...\n");
    initialise_tasking();
 
    monitor_write("Testing the CPU...\n");
    detect_cpu();
    
    monitor_write("Current process PID is: ");
    monitor_write_hex(getpid());
    monitor_write("\n");

    monitor_write("Entering user mode...\n");
    switch_to_user_mode();
    return 0;
}
